﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Text.RegularExpressions;
/// <summary>
///WebMake 的摘要说明
/// </summary>
public class WebMake
{
	public WebMake()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    /// <summary>
    /// 获得模板
    /// </summary>
    /// <param name="sMajorID">专业ID号</param>
    /// <returns></returns>
    public static ModelInfo getModelInfo(string sMajorID)
    {
        ModelInfo modelinfo = new ModelInfo();

        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select * from zyk_Majors inner join zyk_Model on Major_ModelName=Model_Name where Major_ID=@majorid";
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        if (dv != null && dv.Count > 0)
        {
            modelinfo.Index = dv[0]["Model_Index"].ToString();
            modelinfo.Foot = dv[0]["Model_Foot"].ToString();
            modelinfo.Head = dv[0]["Model_Head"].ToString();
            modelinfo.Summary = dv[0]["Model_Summary"].ToString();
            modelinfo.NewsList = dv[0]["Model_NewsList"].ToString();
            modelinfo.NewsDetail = dv[0]["Model_NewsDetail"].ToString();
            modelinfo.PictureList = dv[0]["Model_PictureList"].ToString();
            modelinfo.CourseList = dv[0]["Model_CourseList"].ToString();
            modelinfo.ResourceDetail = dv[0]["Model_ResourceDetail"].ToString();
            modelinfo.ResourceList = dv[0]["Model_ResourceList"].ToString();
            modelinfo.FileList = dv[0]["Model_FileList"].ToString();
        }
        ds.Dispose();
        dv.Dispose();
        return modelinfo;
    }
    /// <summary>
    /// 读取模板
    /// </summary>
    /// <param name="sModelPath">模板路径</param>
    /// <returns></returns>
    public static string getModel(string sModelPath)
    {
        string sModelMap = HttpContext.Current.Server.MapPath(sModelPath);
        StreamReader sr = new StreamReader(sModelMap);
        string sModelStr = sr.ReadToEnd();
        sr.Close();
        return sModelStr;
    }
    /// <summary>
    /// 增加新闻访问量
    /// </summary>
    /// <param name="newsid">新闻ID号</param>
    public static void addNewsVisit(string newsid)
    {
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.UpdateCommand = "update zyk_News set News_Visit=News_Visit+1 where News_ID=@newsid";
        ds.UpdateParameters.Add("newsid", TypeCode.Int32, newsid);
        ds.Update();
        ds.Dispose();
    }
    /// <summary>
    /// 增加资源访问量
    /// </summary>
    /// <param name="resourceid">资源ID号</param>
    public static void addResourceVisit(string resourceid)
    {
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.UpdateCommand = "update zyk_Resources set Resource_Visit=Resource_Visit+1 where Resource_ID=@resourceid";
        ds.UpdateParameters.Add("resourceid", TypeCode.Int32, resourceid);
        ds.Update();
        ds.Dispose();
    }  
    /// <summary>
    /// 根据新闻类型ID获得类型名称
    /// </summary>
    /// <param name="iNewsType">新闻类型ID</param>
    /// <returns>字符串</returns>
    public static string getNewsTypeName(int iNewsType)
    {
        string sReturn = string.Empty;

        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select NewsType_Name from zyk_NewsType where NewsType_ID=@newstype";
        ds.SelectParameters.Add("newstype", DbType.Int32, iNewsType.ToString());
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);

        if (dv.Count > 0)
        {
            sReturn = dv[0]["NewsType_Name"].ToString();
        }
        dv.Dispose();
        ds.Dispose();
        return sReturn;

    }
    /// <summary>
    /// 获得资源类型名称
    /// </summary>
    /// <param name="iResourceType">类型代码</param>
    /// <returns>名称</returns>
    public static string getResourceTypeName(int iResourceType)
    {
        string sReturn = string.Empty;

        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select ResourceType_Name from zyk_ResourceType where ResourceType_ID=@rstype";
        ds.SelectParameters.Add("rstype", DbType.Int32, iResourceType.ToString());
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);

        if (dv.Count > 0)
        {
            sReturn = dv[0]["ResourceType_Name"].ToString();
        }
        dv.Dispose();
        ds.Dispose();
        return sReturn;

    }
    /// <summary>
    /// 获得新闻列表
    /// </summary>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="iNewsTypeID">新闻类别</param>
    /// <param name="bPaged">是否分页</param>
    /// <param name="iPage">第几页</param>
    /// <param name="iRows">每页行</param>
    /// <param name="iLength">最大字符长度</param>
    /// <returns></returns>
    public static string getNewsList(string sMajorID,int iNewsType, bool bPaged,int iPage, int iRows, int iLength)
    {
        string sReturnStr = "";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select News_ID,News_Title,News_ModifyDate,News_Visit from zyk_News where News_Type like @newstype and News_MajorID=@majorid order by News_Top desc,News_ModifyDate desc";
        ds.SelectParameters.Add("newstype", "%" + iNewsType + "%");
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv=(DataView)ds.Select(DataSourceSelectArguments.Empty);
        string newsid;
        string newstitle;
        string newsclick;
        string newsdate;
        int row=0;
        if (dv != null)
        {
            sReturnStr += "<ul>";
            for (int i = iRows * (iPage-1); i < dv.Count&&row<iRows; i++,row++)
            {
                newsid=dv[i]["News_ID"].ToString();

                newstitle = dv[i]["News_Title"].ToString();
                if(newstitle.Length>iLength)
                    newstitle=newstitle.Substring(0,iLength);
                newsdate = Convert.ToDateTime(dv[i]["News_ModifyDate"].ToString()).ToString("yyyy-MM-dd");
                newsclick=dv[i]["News_Visit"].ToString();
                sReturnStr += "<li><a href='NewsDetail.aspx?NewsID="+newsid+"&majorid="+sMajorID+"'>"+newstitle+"</a> <span class='news_date'>("+newsdate+")</span> <span class='news_click'>"+newsclick+"</span></li>\r\n";
            }
            sReturnStr += "</ul>";
            if (bPaged == true)
            {
                int iPageCount = (int)Math.Ceiling(dv.Count / (iRows*1.0));
                int iNextPage = iPage + 1 > iPageCount ? iPageCount : iPage + 1;
                int iLastPage = iPage - 1 < 1 ? 1 : iPage - 1;
                sReturnStr += "<div class='page'><a href='/NewsList.aspx?majorid=" + sMajorID + "&page=1&newstype=" + iNewsType + "'>[首页]</a> ";
                sReturnStr += " <a href='/NewsList.aspx?majorid=" + sMajorID + "&page=" + iLastPage + "&newstype=" +iNewsType + "'>[上一页]</a> ";
                sReturnStr += " <a href='/NewsList.aspx?majorid=" + sMajorID + "&page=" + iNextPage + "&newstype=" + iNewsType + "'>[下一页]</a> ";
                sReturnStr += " <a href='/NewsList.aspx?majorid=" + sMajorID + "&page=" + iPageCount + "&newstype=" + iNewsType + "'>[尾页]</a> ";
                sReturnStr += " [共" + dv.Count + "条记录] [" + iPage + "/" + iPageCount + "页] [每页" + iRows + "条]</div>";
              }
        }
        ds.Dispose();
        dv.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 替换所有的NewsList标记
    /// </summary>
    /// <param name="sHtml">文档</param>
    /// <param name="sMajorID">专业</param>
    /// <param name="Request">请求</param>
    /// <returns></returns>
    public static string ReplaceNewsListTag(string sHtml,string sMajorID,HttpRequest Request)
    {
        int iQueryPage=0,iQueryNewsID=-1;
        //获取QueryString中传递的参数page
        if (Request.QueryString["page"] != null)
            iQueryPage = Convert.ToInt32(Request.QueryString["page"].ToString());
        //获取QueryString中传递的参数newstype
        if(Request.QueryString["newstype"]!=null)
            iQueryNewsID =  Convert.ToInt32(Request.QueryString["newstype"].ToString());

        string sNewsListReg = "(<#NEWSLIST\\s*ID=[0-9]*&PAGED=[a-zA-Z]*&PAGE=[0-9]*&ROWS=[0-9]*&LENGTH=[0-9]*>)";
        string sNewsListReg2 = "<#NEWSLIST\\s*ID=([0-9]*)&PAGED=([a-zA-Z]*)&PAGE=([0-9]*)&ROWS=([0-9]*)&LENGTH=([0-9]*)>";
        Match match;
        Match match2;
        string sNewsTag;
        int iNewsID;
        bool bPaged;
        int iPage;
        int iRows;
        int iLength;
        match = Regex.Match(sHtml, sNewsListReg, RegexOptions.IgnoreCase | RegexOptions.Multiline);
        while (match.Success)
        {
            sNewsTag = match.Groups[1].ToString();
            match2 = Regex.Match(sNewsTag, sNewsListReg2, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (match2.Success)
            {
                if (iQueryNewsID > -1)
                    iNewsID = iQueryNewsID;
                else
                    iNewsID = Convert.ToInt32(match2.Groups[1].ToString());

                if (match2.Groups[2].ToString().ToLower() == "true")
                    bPaged = true;
                else
                    bPaged = false;
                
                //如果querystring 有参数传递过来。
                if (iQueryPage > 0)
                    iPage = iQueryPage;
                else
                    iPage = Convert.ToInt32(match2.Groups[3].ToString());

                iRows = Convert.ToInt32(match2.Groups[4].ToString());
                iLength = Convert.ToInt32(match2.Groups[5].ToString());
                sHtml = sHtml.Replace(sNewsTag, WebMake.getNewsList(sMajorID, iNewsID, bPaged, iPage, iRows, iLength));
            }
            match = match.NextMatch();
        }
        return sHtml;
    }
    /// <summary>
    /// 替换所有的NewsHint标记
    /// </summary>
    /// <param name="sHtml">原始html</param>
    /// <param name="sMajorID">专业代码</param>
    /// <returns>替换后文本</returns>
    public static string ReplaceNewsHintTag(string sHtml, string sMajorID)
    {
        string sReg = "(<#NEWSHINT\\s*TYPE=[A-Za-z]*&ROWS=[0-9]*&LENGTH=[0-9]*>)";
        string sReg2 = "<#NEWSHINT\\s*TYPE=([A-Za-z]*)&ROWS=([0-9]*)&LENGTH=([0-9]*)>";
        Match match;
        Match match2;
        string sTag;
        string sType;
        int iRows;
        int iLength;
        match = Regex.Match(sHtml, sReg, RegexOptions.IgnoreCase | RegexOptions.Multiline);
        while (match.Success)
        {
            sTag = match.Groups[1].ToString();
            match2 = Regex.Match(sTag, sReg2, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (match2.Success)
            {
                sType = match2.Groups[1].ToString().ToLower();
                iRows = Convert.ToInt32(match2.Groups[2].ToString());
                iLength = Convert.ToInt32(match2.Groups[3].ToString());
                sHtml = sHtml.Replace(sTag, WebMake.getNewsHint(sMajorID,sType, iRows, iLength));
            }
            match = match.NextMatch();
        }
        return sHtml;
    }
    /// <summary>
    /// 获得所有的NewsHint 列表
    /// </summary>
    /// <param name="sMajorID">专业</param>
    /// <param name="sType">类型</param>
    /// <param name="iRow">返回行</param>
    /// <param name="iLength">长度</param>
    /// <returns></returns>
    public static string getNewsHint(string sMajorID, string sType, int iRow, int iLength)
    {
        string sReturnStr = "";
        string sURLStr = "NewsDetail.aspx?NewsID=";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        switch (sType)
        {
            case "nlast":
                ds.SelectCommand = "select top " + iRow + " News_Title,News_ID,SUBSTRING(DATENAME(yy,News_ModifyDate), 3, 2) + '/' + DATENAME(mm,News_ModifyDate) + '/' + DATENAME(dd, News_ModifyDate) from zyk_News where News_MajorID='" + sMajorID + "' order by News_ModifyDate desc";
                sURLStr = "NewsDetail.aspx?NewsID=";
                break;
            case "ngood":
                ds.SelectCommand = "select top " + iRow + " News_Title,News_ID,News_Visit from zyk_News  where News_Good=1 and News_MajorID='" + sMajorID + "' order by News_ModifyDate desc ";
                sURLStr = "NewsDetail.aspx?NewsID=";
                break;
            case "rlast":
                ds.SelectCommand = "select top " + iRow + " Resource_Name,Resource_ID,SUBSTRING(DATENAME(yy, Resource_AddDate), 3, 2) + '/' + DATENAME(mm,Resource_AddDate) + '/' + DATENAME(dd, Resource_AddDate) as Resource_Date from zyk_Resources  where  Resource_MajorID='" + sMajorID + "' order by Resource_AddDate desc ";
                sURLStr = "ResourceDetail.aspx?ResourceID=";
                break;
            case "rgood":
                ds.SelectCommand = "select top " + iRow + " Resource_Name,Resource_ID,Resource_Visit  from zyk_Resources where Resource_Good=1 and  Resource_MajorID='" + sMajorID + "' order by Resource_AddDate desc";
                sURLStr = "ResourceDetail.aspx?ResourceID=";
                break;
                //热门资源、热门信息
            case "nhot":
                ds.SelectCommand = "select top " + iRow + " News_Title,News_ID,News_Visit from zyk_News where News_MajorID='" + sMajorID + "' order by News_Visit desc";
                sURLStr = "NewsDetail.aspx?NewsID=";
                break;
            case "rhot":
                ds.SelectCommand = "select top " + iRow + " Resource_Name,Resource_ID,Resource_Visit from zyk_Resources  where  Resource_MajorID='" + sMajorID + "' order by Resource_Visit desc";
                sURLStr = "ResourceDetail.aspx?ResourceID=";
                break;

            default:
                ds.SelectCommand = "select top " + iRow + " News_Title,News_ID,News_Visit from zyk_News where News_MajorID='" + sMajorID + "' order by News_ModifyDate desc";
                sURLStr = "NewsDetail.aspx?NewsID=";
                break;
        }
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string newsid;
        string newstitle;
        string newsclick;
        if (dv != null)
        {
            sReturnStr += "<ul>";
            for (int i =0; i < dv.Count; i++)
            {
                newstitle = dv[i][0].ToString();
                newsid = dv[i][1].ToString();
                if (newstitle.Length > iLength)
                    newstitle = newstitle.Substring(0, iLength);
                newsclick = dv[i][2].ToString();
                sReturnStr += "<li><a href='"+sURLStr + newsid + "&majorid="+sMajorID+"'>" + newstitle + "</a> <span class='hint_click'>" + newsclick + "</span></li>\r\n";
            }
            sReturnStr += "</ul>";
        }
        ds.Dispose();
        dv.Dispose();
        return sReturnStr;

    }
    /// <summary>
    /// 替换图片标记
    /// </summary>
    /// <param name="sHtml">输入内容</param>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="Request">请求</param>
    /// <returns>处理后文本</returns>
    public static string ReplacePictureListTag(string sHtml, string sMajorID, HttpRequest Request)
    {
        int iQueryPage = 0;
        int iQueryCourseID = -1;
        //获取QueryString中传递的参数page
        if (Request.QueryString["page"] != null)
            iQueryPage = Convert.ToInt32(Request.QueryString["page"].ToString());

        if (Request.QueryString["courseid"] != null)
            iQueryCourseID = Convert.ToInt32(Request.QueryString["courseid"].ToString());
        //	<#PICTURELIST ID=68&ORDER=TIME&PAGED=TRUE&PAGE=1&ROWS=8&LENGTH=10>	
        string sReg = "(<#PICTURELIST\\s*ID=[0-9]*&TYPE=[a-zA-Z]*&PAGED=[a-zA-Z]*&PAGE=[0-9]*&ROWS=[0-9]*&LENGTH=[0-9]*>)";
        string sReg2 = "<#PICTURELIST\\s*ID=([0-9]*)&TYPE=([a-zA-Z]*)&PAGED=([a-zA-Z]*)&PAGE=([0-9]*)&ROWS=([0-9]*)&LENGTH=([0-9]*)>";
        Match match;
        Match match2;
        string sTag;
        string sOrder;
        int iResourceType;
        bool bPaged;
        int iPage;
        int iRows;
        int iLength;
        match = Regex.Match(sHtml, sReg, RegexOptions.IgnoreCase | RegexOptions.Multiline);
        while (match.Success)
        {
            sTag = match.Groups[1].ToString();
            match2 = Regex.Match(sTag, sReg2, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (match2.Success)
            {

                iResourceType = Convert.ToInt32(match2.Groups[1].ToString());
                sOrder = match2.Groups[2].ToString().ToLower();
                if (match2.Groups[3].ToString().ToLower() == "true")
                    bPaged = true;
                else
                    bPaged = false;
                //如果querystring 有参数传递过来。
                if (iQueryPage > 0)
                    iPage = iQueryPage;
                else
                    iPage = Convert.ToInt32(match2.Groups[4].ToString());

                iRows = Convert.ToInt32(match2.Groups[5].ToString());

                iLength = Convert.ToInt32(match2.Groups[6].ToString());
                sHtml = sHtml.Replace(sTag, WebMake.getPictureList(sMajorID,iResourceType,iQueryCourseID, bPaged, iPage, iRows,sOrder,iLength));
            }
            match = match.NextMatch();
        }
        return sHtml;
    }
    /// <summary>
    /// 获得图片列表
    /// </summary>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="iResourceType">资源类型</param>
    /// <param name="bPaged">是否分页</param>
    /// <param name="iPage">页数</param>
    /// <param name="sType">排序类型</param>
    /// <returns></returns>
    public static string getPictureList(string sMajorID, int iResourceType,int iCourseID, bool bPaged, int iPage, int iRows,string sType,int iLength)
    {
        /*生成格式：
         * <div class="piclist">
         * <div><img src="/" alt="" width="100px" height="100px" /></div>
         * <div>图片名称</div>
         * <div>下载 预览</div>
         * </div>	    
	    */
        string sReturnStr = "";
        string sCourseQuery = "";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        if (iCourseID > 0)
            sCourseQuery = " and exists (select * from zyk_RCR where RCR_CourseID=" + iCourseID + " and RCR_ResourceID=Resource_ID)";
        switch(sType)
        {
            case "last":
                ds.SelectCommand = "select  Resource_ID,Resource_Name,Resource_URL from zyk_Resources where Resource_Type like @resourcetype " + sCourseQuery + " and Resource_MajorID=@majorid order by Resource_Top desc,Resource_AddDate desc";
                break;
            case "good":
                ds.SelectCommand = "select  Resource_ID, Resource_Name,Resource_URL from zyk_Resources where Resource_Good=1 " + sCourseQuery + " and Resource_Type like @resourcetype and Resource_MajorID=@majorid order by Resource_Top desc,Resource_AddDate desc";
                break;
            case "hot":
                ds.SelectCommand = "select  Resource_ID, Resource_Name,Resource_URL from zyk_Resources where Resource_Type like @resourcetype " + sCourseQuery + " and Resource_MajorID=@majorid order by Resource_Top desc,Resource_Visit desc";
                break;
            default:
                ds.SelectCommand = "select Resource_ID,Resource_Name,Resource_URL from zyk_Resources where Resource_Type like @resourcetype " + sCourseQuery + " and Resource_MajorID=@majorid order by Resource_Top desc,Resource_AddDate desc";
                break;

        }           
        ds.SelectParameters.Add("resourcetype", "%{"+iResourceType+"}%");
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string resourceurl;
        string resourcename;
        string resourceid;
        int row=0;
        if (dv != null && dv.Count > 0)
        {
            for (int i = iRows * (iPage - 1); i < dv.Count && row < iRows; i++, row++)
            {

                resourceid = dv[i]["Resource_ID"].ToString();
                resourcename = dv[i]["Resource_Name"].ToString();
                if(resourcename.Length>iLength)
                    resourcename=resourcename.Substring(0,iLength);
                resourceurl = dv[i]["Resource_URL"].ToString();
                sReturnStr += "<div class=\"piclist\">\r\n";
                sReturnStr += "<div><img src='"+resourceurl+"' alt='"+resourcename+"' width='100px' height='100px' /></div>\r\n";
                sReturnStr += "<div>"+resourcename+"</div>\r\n";
                sReturnStr += "<div><a href='/DownLoad.aspx?id="+resourceid+"'>下载</a> <a href='"+resourceurl+"'>预览</a></div>\r\n";
                sReturnStr += "</div>\r\n";
            }
            if (bPaged == true)
            {
                int iPageCount = (int)Math.Ceiling(dv.Count / (iRows * 1.0));
                int iNextPage = iPage + 1 > iPageCount ? iPageCount : iPage + 1;
                int iLastPage = iPage - 1 < 1 ? 1 : iPage - 1;

                sReturnStr += "<div class='page'><a href='/PictureList.aspx?majorid=" + sMajorID + "&page=1&resourcetype=" + iResourceType + "'>[首页]</a> ";
                sReturnStr += " <a href='/PictureList.aspx?majorid=" + sMajorID + "&page=" + iLastPage + "&resourcetype=" + iResourceType + "'>[上一页]</a> ";
                sReturnStr += " <a href='/PictureList.aspx?majorid=" + sMajorID + "&page=" + iNextPage + "&resourcetype=" + iResourceType + "'>[下一页]</a> ";
                sReturnStr += " <a href='/PictureList.aspx?majorid=" + sMajorID + "&page=" + iPageCount + "&resourcetype=" + iResourceType + "'>[尾页]</a> ";
                sReturnStr += " [共" + dv.Count + "条记录] [" + iPage + "/" + iPageCount + "页] [每页" + iRows + "条]</div>";
                }
        }

        dv.Dispose();
        ds.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 替换课程列表
    /// </summary>
    /// <param name="sHtml">源内容</param>
    /// <param name="sMajorID">专业ID</param>
    /// <param name="Request">请求</param>
    /// <returns></returns>
    public static string ReplaceCourseListTag(string sHtml, string sMajorID, HttpRequest Request)
    {
        int iQueryPage = 0;
        int iQueryResourceType = -1;
        //获取QueryString中传递的参数page
        if (Request.QueryString["page"] != null)
            iQueryPage = Convert.ToInt32(Request.QueryString["page"].ToString());
        if (Request.QueryString["resourcetype"] != null)
            iQueryResourceType = Convert.ToInt32(Request.QueryString["resourcetype"].ToString());
        //<#COURSELIST ID=234&PAGED=TRUE&PAGE=1&ROWS=20>
        string sReg = "(<#COURSELIST\\s*ID=[0-9]*&PAGED=[a-zA-Z]*&PAGE=[0-9]*&ROWS=[0-9]*>)";
        string sReg2 = "<#COURSELIST\\s*ID=([0-9]*)&PAGED=([a-zA-Z]*)&PAGE=([0-9]*)&ROWS=([0-9]*)>";
        Match match;
        Match match2;
        string sTag;
        int iResourceType;
        bool bPaged;
        int iPage;
        int iRows;
        match = Regex.Match(sHtml, sReg, RegexOptions.IgnoreCase | RegexOptions.Multiline);
        while (match.Success)
        {
            sTag = match.Groups[1].ToString();
            match2 = Regex.Match(sTag, sReg2, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (match2.Success)
            {
                //如果有参数传递
                if (iQueryResourceType >= 0)
                    iResourceType = iQueryResourceType;
                else 
                    iResourceType = Convert.ToInt32(match2.Groups[1].ToString());

                if (match2.Groups[2].ToString().ToLower() == "true")
                    bPaged = true;
                else
                    bPaged = false;
                //如果querystring 有参数传递过来。
                if (iQueryPage > 0)
                    iPage = iQueryPage;
                else
                    iPage = Convert.ToInt32(match2.Groups[3].ToString());          

                iRows = Convert.ToInt32(match2.Groups[4].ToString());

                sHtml = sHtml.Replace(sTag, WebMake.getCourseList(sMajorID, iResourceType, bPaged, iPage, iRows));
            }
            match = match.NextMatch();
        }
        return sHtml;
    }
    /// <summary>
    /// 获得课程列表
    /// </summary>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="iResourceType">资源类型</param>
    /// <param name="bPaged">是否分页</param>
    /// <param name="iPage">页码</param>
    /// <param name="iRows">行数</param>
    /// <returns></returns>
    public static string getCourseList(string sMajorID, int iResourceType, bool bPaged, int iPage, int iRows)
    {
        /* 生成格式
         * <ul id="table">
         * <li>课程名称</li>
         * <li class="other">课程简介</li>
         * <li class="other">进入课程</li>
         * </ul>
         * <div class="page"> 共几条 ，当前第1/2 每页20条 首页  上一页  下一页 尾页</div>
         */
        string sReturnStr = "";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select Resource_ID,Resource_Name,Resource_Redirect from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid";
        ds.SelectParameters.Add("rstype", "%{" + iResourceType + "}%");
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string rsid;
        string rsname;
        string rsurl;
        int row = 0;
        if (dv != null)
        {
            sReturnStr += "<ul id='table'>";
            for (int i = iRows * (iPage - 1); i < dv.Count && row < iRows; i++, row++)
            {
                rsid = dv[i]["Resource_ID"].ToString();
                rsname = dv[i]["Resource_Name"].ToString();
                rsurl = dv[i]["Resource_Redirect"].ToString();
                sReturnStr += "<li>"+rsname+"</li>";
                sReturnStr += "<li class='other'><a href='ResourceDetail.aspx?ResourceID=" + rsid + "&MajorID=" + sMajorID + "'>课程简介</a></li>";
                sReturnStr += "<li class='other'><a href='"+rsurl+"'>进入课程</a></li>";
            }
            sReturnStr += "</ul>";
            if (bPaged == true)
            {
                int iPageCount = (int)Math.Ceiling(dv.Count / (iRows * 1.0));
                int iNextPage = iPage + 1 > iPageCount ? iPageCount : iPage + 1;
                int iLastPage = iPage - 1 < 1 ? 1 : iPage - 1;

                sReturnStr += "<div class='page'><a href='/CourseList.aspx?majorid=" + sMajorID + "&page=1&resourcetype=" + iResourceType + "'>[首页]</a> ";
                sReturnStr += " <a href='/CourseList.aspx?majorid=" + sMajorID + "&page=" + iLastPage + "&resourcetype=" + iResourceType + "'>[上一页]</a> ";
                sReturnStr += " <a href='/CourseList.aspx?majorid=" + sMajorID + "&page=" + iNextPage + "&resourcetype=" + iResourceType + "'>[下一页]</a> ";
                sReturnStr += " <a href='/CourseList.aspx?majorid=" + sMajorID + "&page=" + iPageCount + "&resourcetype=" + iResourceType + "'>[尾页]</a> ";
                sReturnStr += " [共" + dv.Count + "条记录] [" + iPage + "/" + iPageCount + "页] [每页" + iRows + "条]</div>";
            }
        }
        ds.Dispose();
        dv.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 替换所有标记
    /// </summary>
    /// <param name="sHtml">源代码</param>
    /// <param name="modelInfo">模板信息</param>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="Request">信息</param>
    /// <returns></returns>
    public static string ReplaceAllTag(string sHtml,ModelInfo modelInfo,string sMajorID,HttpRequest Request)
    {
        string sHead = WebMake.getModel(modelInfo.Head);
        string sSummary = WebMake.getModel(modelInfo.Summary);
        string sFoot = WebMake.getModel(modelInfo.Foot);
        sHtml = sHtml.Replace("<#HEAD>", sHead);
        sHtml = sHtml.Replace("<#FOOT>", sFoot);
        sHtml = sHtml.Replace("<#MAJORID>", sMajorID);
        sHtml = sHtml.Replace("<#SUMMARY>", sSummary);
        sHtml = sHtml.Replace("<#MAJORNAME>", WebMake.getMajorName(sMajorID));
        //两个类型
        if(Request.QueryString["resourcetype"]!=null){
            sHtml = sHtml.Replace("<#RESOURCETYPE>", Request.QueryString["resourcetype"].ToString());    
        }
        if(Request.QueryString["newstype"]!=null){
            sHtml = sHtml.Replace("<#NEWSTYPENAME>", WebMake.getNewsTypeName(Convert.ToInt32(Request.QueryString["newstype"].ToString())));
            sHtml = sHtml.Replace("<#TYPE>", WebMake.getNewsTypeName(Convert.ToInt32(Request.QueryString["newstype"].ToString())));
	}
        if (Request.QueryString["resourcetype"] != null){
            sHtml = sHtml.Replace("<#RESOURCETYPENAME>", WebMake.getResourceTypeName(Convert.ToInt32(Request.QueryString["resourcetype"].ToString())));
            sHtml = sHtml.Replace("<#TYPE>", WebMake.getResourceTypeName(Convert.ToInt32(Request.QueryString["resourcetype"].ToString())));
}
        sHtml = WebMake.ReplaceNewsListTag(sHtml, sMajorID, Request);
        sHtml = WebMake.ReplaceNewsHintTag(sHtml, sMajorID);
        sHtml = WebMake.ReplacePictureListTag(sHtml, sMajorID, Request);
        sHtml = WebMake.ReplaceCourseListTag(sHtml, sMajorID, Request);
        sHtml = WebMake.ReplaceResourceListTag(sHtml, sMajorID, Request);
        sHtml = WebMake.ReplaceMajorCourseListTag(sHtml, sMajorID, Request);
        sHtml = WebMake.ReplaceFileListTag(sHtml, sMajorID, Request);
        return sHtml;
    }
    public static string getMajorName(string sMajorID)
    {
        string sReturnStr = "";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "SELECT * from zyk_Majors where Major_ID=@majorid";
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        if (dv != null && dv.Count > 0)
        {
            sReturnStr = dv[0]["Major_Name"].ToString();
        }
        dv.Dispose();
        ds.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 获取文件类型
    /// </summary>
    /// <param name="sFileName">文件名称</param>
    /// <returns></returns>
    public static string getFileType(string sFileName)
    {
        return sFileName!=""?sFileName.Substring(sFileName.LastIndexOf('.'), sFileName.Length - sFileName.LastIndexOf('.')):"无";
    }
    /// <summary>
    /// 获取指定资源的所属课程
    /// </summary>
    /// <param name="sResourceID">资源ID</param>
    /// <returns></returns>
    public static string getResourceCourseName(string sResourceID)
    {
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "SELECT zyk_Courses.Course_Name FROM zyk_RCR INNER JOIN zyk_Courses ON zyk_Courses.Course_ID = zyk_RCR.RCR_CourseID where RCR_ResourceID=@rsid";
        ds.SelectParameters.Add("rsid", sResourceID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string sReturnStr="";
        if (dv != null && dv.Count > 0)
        {
            for (int i = 0; i < dv.Count; i++)
                sReturnStr += " " + dv[i]["Course_Name"].ToString();
        }
        dv.Dispose();
        ds.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 替换资源列表TAG
    /// </summary>
    /// <param name="sHtml">原内容</param>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="Request">请求</param>
    /// <returns></returns>
    public static string ReplaceResourceListTag(string sHtml, string sMajorID, HttpRequest Request)
    {
        int iQueryPage = 0;
        int iQueryResourceType = -1;
        int iQueryCourseID = -1;
        //获取QueryString中传递的参数page
        if (Request.QueryString["page"] != null)
            iQueryPage = Convert.ToInt32(Request.QueryString["page"].ToString());
        if (Request.QueryString["resourcetype"] != null)
            iQueryResourceType = Convert.ToInt32(Request.QueryString["resourcetype"].ToString());
        if(Request.QueryString["courseid"]!=null)
            iQueryCourseID = Convert.ToInt32(Request.QueryString["courseid"].ToString());
        //<#COURSELIST ID=234&PAGED=TRUE&PAGE=1&ROWS=20>
        string sReg = "(<#RESOURCELIST\\s*ID=[0-9]*&TYPE=[A-Za-z]*&PAGED=[a-zA-Z]*&PAGE=[0-9]*&ROWS=[0-9]*&LENGTH=[0-9]*>)";
        string sReg2 = "<#RESOURCELIST\\s*ID=([0-9]*)&TYPE=([A-Za-z]*)&PAGED=([a-zA-Z]*)&PAGE=([0-9]*)&ROWS=([0-9]*)&LENGTH=([0-9]*)>";
        Match match;
        Match match2;
        string sTag;
        int iResourceType;
        bool bPaged;
        int iPage;
        int iRows;
        int iLength;
        string sType;
        match = Regex.Match(sHtml, sReg, RegexOptions.IgnoreCase | RegexOptions.Multiline);
        while (match.Success)
        {
            sTag = match.Groups[1].ToString();
            match2 = Regex.Match(sTag, sReg2, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (match2.Success)
            {
                //如果有参数传递
                if (iQueryResourceType >= 0)
                    iResourceType = iQueryResourceType;
                else
                    iResourceType = Convert.ToInt32(match2.Groups[1].ToString());
                sType = match2.Groups[2].ToString().ToLower();
                if (match2.Groups[3].ToString().ToLower() == "true")
                    bPaged = true;
                else
                    bPaged = false;
                //如果querystring 有参数传递过来。
                if (iQueryPage > 0)
                    iPage = iQueryPage;
                else
                    iPage = Convert.ToInt32(match2.Groups[4].ToString());

                iRows = Convert.ToInt32(match2.Groups[5].ToString());
                iLength= Convert.ToInt32(match2.Groups[6].ToString());
                sHtml = sHtml.Replace(sTag, WebMake.getResourceList(sMajorID, iResourceType,sType,iQueryCourseID, bPaged, iPage, iRows,iLength));
            }
            match = match.NextMatch();
        }
        return sHtml;
    }
    /// <summary>
    /// 获取资源列表
    /// </summary>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="iResourceType">资源类型</param>
    /// <param name="bPaged">是否分页</param>
    /// <param name="iPage">页码</param>
    /// <param name="iRows">行数</param>
    /// <param name="iLength">长度</param>
    /// <returns></returns>
    public static string getResourceList(string sMajorID, int iResourceType,string sType,int iCourseID, bool bPaged, int iPage, int iRows,int iLength)
    {
        /* 生成格式
        * <table>
        * <tr>
        * <th>类型</th>
        * <th>资源名称 </th>
        * <th>入库时间</th>
        * <th>访问量</th>
        * <th>大小（KB）</th>
        *</tr>
        *</table>
        * <div class="page"> 共1条 每页20条 上一页  下一页 </div>
        */
        string sReturnStr = "";
        string sCourseQuery = "";
        if (iCourseID > 0)
            sCourseQuery = " and exists (select * from zyk_RCR where RCR_CourseID="+iCourseID+" and RCR_ResourceID=Resource_ID)";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        switch (sType)
        {
            case "last":
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_AddDate desc";
                break;
            case "good":
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_Good=1 and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_AddDate desc";
                break;
            case "hot":
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_Visit desc";
                break;
            default:
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_AddDate desc";
                break;
        }
        
        ds.SelectParameters.Add("rstype", "%{" + iResourceType + "}%");
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string rsid;
        string rsname;
        string rsurl;
        string rsvisit;
        string rssize;
        string rsadd;
        int row = 0;
        if (dv != null)
        {
            sReturnStr += "<table><tr>\r\n";
            sReturnStr += "<th class='resource_type'>类型</th><th class='resource_name'>资源名称 </th><th class='resource_date'>入库时间</th><th class='resource_click'>点击数</th><th class='resource_size'>大小</th><th class='resource_operate'>操作</th></tr>";
            for (int i = iRows * (iPage - 1); i < dv.Count && row < iRows; i++, row++)
            {
                rsid = dv[i]["Resource_ID"].ToString();
                rsname = dv[i]["Resource_Name"].ToString();
                if (rsname.Length > iLength)
                    rsname = rsname.Substring(0, iLength);

                rsurl = dv[i]["Resource_URL"].ToString();
                rsvisit = dv[i]["Resource_Visit"].ToString();
                rssize = dv[i]["Resource_Size"].ToString();
                if (Convert.ToInt16(rssize) > 1024)
                    rssize = ((int)Convert.ToInt16(rssize) / 10) / 100.0 + "M";
                else
                    rssize = rssize + "K";
                rsadd = Convert.ToDateTime(dv[i]["Resource_AddDate"].ToString()).ToString("yyyy-MM-dd");
                sReturnStr += "<tr>";
                sReturnStr += "<td>" + WebMake.getFileType(rsurl) + "</td>";
                sReturnStr += "<td><a href='/ResourceDetail.aspx?resourceid="+rsid+"&majorid="+sMajorID+"'>"+rsname+ "</a></td>";
                sReturnStr += "<td>" + rsadd + "</td>";
                sReturnStr += "<td>" +rsvisit + "</td>";
                sReturnStr += "<td>" + rssize+ "</td>";
                sReturnStr += "<td><a href='/DownLoad.aspx?id="+rsid+"'>下载</a></td>";
                sReturnStr += "</tr>";
            }
            sReturnStr += "</table>";
            if (bPaged == true)
            {
                int iPageCount = (int)Math.Ceiling(dv.Count / (iRows * 1.0));
                int iNextPage = iPage + 1 > iPageCount ? iPageCount : iPage + 1;
                int iLastPage = iPage - 1 < 1 ? 1 : iPage - 1;

                sReturnStr += "<div class='page'><a href='/ResourceList.aspx?majorid=" + sMajorID + "&page=1&resourcetype=" + iResourceType + "'>[首页]</a> ";
                sReturnStr+=" <a href='/ResourceList.aspx?majorid=" + sMajorID + "&page=" + iLastPage + "&resourcetype=" + iResourceType + "'>[上一页]</a> ";
                sReturnStr+=" <a href='/ResourceList.aspx?majorid=" + sMajorID + "&page=" + iNextPage + "&resourcetype=" + iResourceType + "'>[下一页]</a> ";
                sReturnStr+=" <a href='/ResourceList.aspx?majorid=" + sMajorID + "&page=" + iPageCount + "&resourcetype=" + iResourceType + "'>[尾页]</a> ";
                sReturnStr+=" [共" + dv.Count + "条记录] [" + iPage + "/" + iPageCount + "页] [每页"+iRows+"条]</div>";
            }
        }
        ds.Dispose();
        dv.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 获得专业课程列表
    /// </summary>
    /// <param name="sHtml">源内容</param>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="Request">请求</param>
    /// <returns></returns>
    public static string ReplaceMajorCourseListTag(string sHtml,string sMajorID,HttpRequest Request)
    {
        /*<ul><li><a href='ResourceList.aspx?majorid=640101&resourcetype=1&courseid=1'></a></li></ul>*/

        string sReplaceContent="";
        string sQueryURL = Request.Path.ToString();
        string sQueryType = "";
        if (Request.QueryString["resourcetype"] != null)
            sQueryType = "&resourcetype=" + Request.QueryString["resourcetype"].ToString();
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select * from zyk_Courses  where Course_MajorID=@majorid";
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string coursename;
        string courseid;
        if (dv != null && dv.Count > 0)
        {
            sReplaceContent += "<ul>";
            for (int i = 0; i < dv.Count; i++)
            {
                coursename = dv[i]["Course_Name"].ToString();
                courseid = dv[i]["Course_ID"].ToString();
                sReplaceContent += "<li><a href='" + sQueryURL + "?majorid=" + sMajorID + sQueryType + "&courseid=" + courseid + "'>" + coursename + "</a></li>";
            }
            sReplaceContent += "</ul>";
        }
        sHtml = sHtml.Replace("<#MAJORCOURSELIST>", sReplaceContent);
        return sHtml;
    }
    /// <summary>
    /// 替换所有的<#FILELIST>TAG
    /// </summary>
    /// <param name="sHtml"></param>
    /// <param name="sMajorID"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    public static string ReplaceFileListTag(string sHtml, string sMajorID, HttpRequest Request)
    {
        int iQueryPage = 0;
        int iQueryResourceType = -1;
        int iQueryCourseID = -1;
        //获取QueryString中传递的参数page
        if (Request.QueryString["page"] != null)
            iQueryPage = Convert.ToInt32(Request.QueryString["page"].ToString());
        if (Request.QueryString["resourcetype"] != null)
            iQueryResourceType = Convert.ToInt32(Request.QueryString["resourcetype"].ToString());
        if (Request.QueryString["courseid"] != null)
            iQueryCourseID = Convert.ToInt32(Request.QueryString["courseid"].ToString());
        //<#COURSELIST ID=234&PAGED=TRUE&PAGE=1&ROWS=20>
        string sReg = "(<#FILELIST\\s*ID=[0-9]*&TYPE=[A-Za-z]*&PAGED=[a-zA-Z]*&PAGE=[0-9]*&ROWS=[0-9]*&LENGTH=[0-9]*>)";
        string sReg2 = "<#FILELIST\\s*ID=([0-9]*)&TYPE=([A-Za-z]*)&PAGED=([a-zA-Z]*)&PAGE=([0-9]*)&ROWS=([0-9]*)&LENGTH=([0-9]*)>";
        Match match;
        Match match2;
        string sTag;
        int iResourceType;
        bool bPaged;
        int iPage;
        int iRows;
        int iLength;
        string sType;
        match = Regex.Match(sHtml, sReg, RegexOptions.IgnoreCase | RegexOptions.Multiline);
        while (match.Success)
        {
            sTag = match.Groups[1].ToString();
            match2 = Regex.Match(sTag, sReg2, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if (match2.Success)
            {
                //如果有参数传递
                if (iQueryResourceType >= 0)
                    iResourceType = iQueryResourceType;
                else
                    iResourceType = Convert.ToInt32(match2.Groups[1].ToString());
                sType = match2.Groups[2].ToString().ToLower();
                if (match2.Groups[3].ToString().ToLower() == "true")
                    bPaged = true;
                else
                    bPaged = false;
                //如果querystring 有参数传递过来。
                if (iQueryPage > 0)
                    iPage = iQueryPage;
                else
                    iPage = Convert.ToInt32(match2.Groups[4].ToString());

                iRows = Convert.ToInt32(match2.Groups[5].ToString());
                iLength = Convert.ToInt32(match2.Groups[6].ToString());
                sHtml = sHtml.Replace(sTag, WebMake.getFileList(sMajorID, iResourceType, sType, iQueryCourseID, bPaged, iPage, iRows, iLength));
            }
            match = match.NextMatch();
        }
        return sHtml;
    }
    /// <summary>
    /// 获取文章列表
    /// </summary>
    /// <param name="sMajorID">专业代码</param>
    /// <param name="iResourceType">资源类型</param>
    /// <param name="bPaged">是否分页</param>
    /// <param name="iPage">页码</param>
    /// <param name="iRows">行数</param>
    /// <param name="iLength">长度</param>
    /// <returns></returns>
    public static string getFileList(string sMajorID, int iResourceType, string sType, int iCourseID, bool bPaged, int iPage, int iRows, int iLength)
    {
        /* 生成格式
        * <table>
        * <tr>
        * <td><a href='/ResourceDetail.aspx?MajorID=590202&ResourceID=451'>资源名称</a></td>
        * <td>时间</td>
        *</tr>
        *</table>
        * <div class="page"> 共1条 每页20条 上一页  下一页 </div>
        */
        string sReturnStr = "";
        string sCourseQuery = "";
        if (iCourseID > 0)
            sCourseQuery = " and exists (select * from zyk_RCR where RCR_CourseID=" + iCourseID + " and RCR_ResourceID=Resource_ID)";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        switch (sType)
        {
            case "last":
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_AddDate desc";
                break;
            case "good":
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_Good=1 and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_AddDate desc";
                break;
            case "hot":
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_Visit desc";
                break;
            default:
                ds.SelectCommand = "select * from zyk_Resources  where Resource_Type like @rstype and Resource_MajorID=@majorid " + sCourseQuery + " order by Resource_Top desc,Resource_AddDate desc";
                break;
        }

        ds.SelectParameters.Add("rstype", "%{" + iResourceType + "}%");
        ds.SelectParameters.Add("majorid", sMajorID);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        string rsid;
        string rsname;
        string rsadd;
        int row = 0;
        if (dv != null)
        {
            sReturnStr += "<table>\r\n";
            for (int i = iRows * (iPage - 1); i < dv.Count && row < iRows; i++, row++)
            {
                rsid = dv[i]["Resource_ID"].ToString();
                rsname = dv[i]["Resource_Name"].ToString();
                if (rsname.Length > iLength)
                    rsname = rsname.Substring(0, iLength);
                if(sType=="hot")
                    rsadd = dv[i]["Resource_Visit"].ToString();
                else
                    rsadd = Convert.ToDateTime(dv[i]["Resource_AddDate"].ToString()).ToString("yyyy-MM-dd");
                sReturnStr += "<tr>";
                sReturnStr += "<td><a href='/ResourceDetail.aspx?resourceid=" + rsid + "&majorid=" + sMajorID + "'>" + rsname + "</a></td>";
                sReturnStr += "<td>" + rsadd + "</td>";
                sReturnStr += "</tr>";
            }
            sReturnStr += "</table>";
            if (bPaged == true)
            {
                int iPageCount = (int)Math.Ceiling(dv.Count / (iRows * 1.0));
                int iNextPage = iPage + 1 > iPageCount ? iPageCount : iPage + 1;
                int iLastPage = iPage - 1 < 1 ? 1 : iPage - 1;

                sReturnStr += "<div class='page'><a href='/FileList.aspx?majorid=" + sMajorID + "&page=1&resourcetype=" + iResourceType + "'>[首页]</a> ";
                sReturnStr += " <a href='/FileList.aspx.aspx?majorid=" + sMajorID + "&page=" + iLastPage + "&resourcetype=" + iResourceType + "'>[上一页]</a> ";
                sReturnStr += " <a href='/FileList.aspx.aspx?majorid=" + sMajorID + "&page=" + iNextPage + "&resourcetype=" + iResourceType + "'>[下一页]</a> ";
                sReturnStr += " <a href='/FileList.aspx.aspx?majorid=" + sMajorID + "&page=" + iPageCount + "&resourcetype=" + iResourceType + "'>[尾页]</a> ";
                sReturnStr += " [共" + dv.Count + "条记录] [" + iPage + "/" + iPageCount + "页] [每页" + iRows + "条]</div>";
            }
        }
        ds.Dispose();
        dv.Dispose();
        return sReturnStr;
    }
    /// <summary>
    /// 根据ID获得地址
    /// </summary>
    /// <param name="sResourceID">资源ID</param>
    /// <returns></returns>
    public static string getResourceURL(string sResourceID)
    {
        string sReturnStr = "";
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select Resource_URL from zyk_Resources where Resource_ID=@resourceid";
        ds.SelectParameters.Add("resourceid",sResourceID );
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        if (dv != null&&dv.Count>0)
        {
            sReturnStr = dv[0][0].ToString();
        }
        return sReturnStr;
    }
}
